package com.cbs.android.module.shit.sample;

import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.widget.TextView;

import com.cbs.android.component.application.activity.CBSActivity;
import com.cbs.android.component.log.L;
import com.cbs.android.module.shit.ShitModule;
import com.cbs.android.module.shit.ShitModuleListener;
import com.cbs.android.module.shit.ShitService;

public class MainActivity2 extends CBSActivity {
    private static final String TAG = MainActivity2.class.getName();
    private ShitService.ShitServiceBinder binder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        ShitModule.bind(this, new ShitModuleListener() {
            @Override
            public void onBinded(IBinder binder) {
                L.e(TAG, "activity.onbinded");
                MainActivity2.this.binder = (ShitService.ShitServiceBinder) binder;
            }

            @Override
            public void onShitUpdated() {
                L.e(TAG, "activity.shit");
                ((TextView) findViewById(R.id.testView)).setText((binder.getShit(0, 1) == null) + "");
            }
        });
    }

    public void open(View view) {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    }
}
